package com.ruyuan.ingestion;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Arrays;

@SpringBootApplication
public class Driver implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(Driver.class,args);
    }

    @Override
    public void run(String... args) throws Exception {
        if (args == null || args.length <1) {
            throw new Exception("参数不满足条件");
        }

        /**
         * java -jar ingestion.jar com.ruyuan.kafka.UserFriendStreamer settings.properties
         * */
        Object o = Class.forName(args[0]).newInstance();
        if (o instanceof IngestionExecutor) {
            ((IngestionExecutor)o).execute(Arrays.copyOfRange(args,1,args.length));
        }else {
            throw new Exception("该对象没有实现IngestionExecutor");
        }
    }
}
